package com.taotao.rop.service;

import com.rop.annotation.HttpAction;
import com.rop.annotation.ServiceMethod;
import com.rop.annotation.ServiceMethodBean;
import com.taotao.rop.database.domain.Role;
import com.taotao.rop.database.mapper.RoleMapper;
import com.taotao.rop.response.BaseResponse;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@ServiceMethodBean(httpAction = HttpAction.POST, version = "1.0")
public class RoleService {
    @Autowired
    private RoleMapper roleMapper;

    @ServiceMethod(method = "role.list")
    public Object listRole(Role request) {
        List<Role> roleList = roleMapper.getList(request);

        BaseResponse<List<Role>> response = new BaseResponse<List<Role>>();
        response.setSuccess(true);
        response.setMsg("" + roleMapper.getCount(request));
        response.setData(roleList);
        return response;
    }

    @ServiceMethod(method = "role.insert")
    public Object insertRole(Role request) {
        Integer count = roleMapper.insertOne(request);

        BaseResponse<Integer> response = new BaseResponse<Integer>();
        response.setSuccess(true);
        response.setData(count);
        return response;
    }

    @ServiceMethod(method = "role.update")
    public Object updateRole(Role request) {
        Integer count = roleMapper.updateOne(request);

        BaseResponse<Integer> response = new BaseResponse<Integer>();
        response.setSuccess(true);
        response.setData(count);
        return response;
    }
}
